package com.br.fsm.projectdelivery.controlador;

import java.util.ArrayList;

import com.br.fsm.projectdelivery.basica.Promocao;
import com.br.fsm.projectdelivery.basica.Promocao.Promocoes;
import com.br.fsm.projectdelivery.excecao.ControladorException;
import com.br.fsm.projectdelivery.excecao.RepositorioException;
import com.br.fsm.projectdelivery.repositorio.IRepositorioPromocoes;
import com.br.fsm.projectdelivery.repositorio.RepositorioPromocoes;

public class ControladorPromocoes extends ControladorBasico implements IControladorPromocoes {

	private IRepositorioPromocoes repositorioPromocoes;
	private static ControladorPromocoes instance;

	private ControladorPromocoes() {
		super();
		repositorioPromocoes = (IRepositorioPromocoes) RepositorioPromocoes
				.getInstance();
	}

	public static ControladorPromocoes getInstance() {
		if (instance == null) {
			instance = new ControladorPromocoes();
		}
		return instance;
	}
	
	@Override
	public Promocao getPromocoesById(int id) throws ControladorException {
		try {
			return repositorioPromocoes.getPromocoesById(id);
		} catch (RepositorioException e) {
			throw new ControladorException(e.getMessage());
		}
	}

	@Override
	public ArrayList<Promocao> getAllPromocoes() throws ControladorException {
		try {
			return repositorioPromocoes.getAllPromocoes();
		} catch (RepositorioException e) {
			throw new ControladorException(e.getMessage());
		}
	}

	@Override
	public void insertPromocoes(Promocoes promocoes) throws ControladorException {
		try {
			repositorioPromocoes.insertPromocoes(promocoes);
		} catch (RepositorioException e) {
			throw new ControladorException(e.getMessage());
		}
	}

	@Override
	public void updatePromocoes(Promocoes promocoes) throws ControladorException {
		try {
			repositorioPromocoes.updatePromocoes(promocoes);
		} catch (RepositorioException e) {
			throw new ControladorException(e.getMessage());
		}
	}

	@Override
	public void removePromocoes(Promocoes promocoes) throws ControladorException {
		try {
			repositorioPromocoes.removePromocoes(promocoes);
		} catch (RepositorioException e) {
			throw new ControladorException(e.getMessage());
		}
	}
}
